import http from "@/api";
import { ResPage, User, OrgManager } from "@/api/interface/index";
import qs from "qs";
/**
 * @name 访问控制模块
 */

// 个人信息详情
export const findUserDetail = (params: {}, header: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  }
  return http.post<String>(`/pages/user!findUserDetail.action`, qs.stringify(newobj)); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 个人信息详情
export const resetPassword = (params: {}, header: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  }
  return http.post<String>(`/pages/user!resetPassword.action`, qs.stringify(newobj)); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 获取树形用户列表
export const getUserTreeList = (params: User.ReqUserParams) => {
  params.page = params.pageNum;
  params.rows = params.pageSize;
  return http.post<ResPage<User.ResUserList>>(
    `/pages/user!find.action?userQueryDto.companyNo=1&_=1719369189256&userQueryDto.orgNo=` +
      params.departmentId +
      `&userQueryDto.lastName=` +
      (params.fullName == undefined ? "" : params.fullName) +
      `&userQueryDto.loginName=` +
      (params.loginName == undefined ? "" : params.loginName),
    {},
    { params }
  );
};

// // 查询角色
// export const roleFind = (params: {}, header: string) => {
//   let newobj = {};
//   if (header != null && header != "") {
//     Object.keys(params).forEach(key => {
//       newobj[header + "." + `${key}`] = `${params[key]}`;
//     });
//   }
//   return http.post<String>(`/pages/role!find.action`, qs.stringify(newobj)); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
// };

/**
 * @name 查询角色
 */
// 查询角色
export const roleFind = (params: {}, header: string, unhandle: string[]) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      if (unhandle.length > 0) {
        if (unhandle.includes(`${key}`)) {
          newobj[`${key}`] = `${params[key]}`;
        } else {
          newobj[header + "." + `${key}`] = `${params[key]}`;
        }
      } else {
        newobj[header + "." + `${key}`] = `${params[key]}`;
      }
    });
  } else {
    newobj = params;
  }
  // return http.post<ResPage<User.ResUserList>>("" + `/pages/itsopUser!findITSOPUserPager.action`, {}, { params });
  return http.postitsm<string>(`/pages/role!find.action`, qs.stringify(newobj));
};

// 角色编号是否存在
export const existByRoleCode = (params: {}, header: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  }
  return http.post<String>(`/pages/role!existByRoleCode.action`, qs.stringify(newobj)); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 角色名称是否存在
export const existByRoleName = (params: {}, header: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  }
  return http.post<String>(`/pages/role!existByRoleName.action`, qs.stringify(newobj)); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 保存角色
export const save = (params: {}, header: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  }
  return http.post<String>(`/pages/role!save.action`, qs.stringify(newobj)); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 编辑角色
export const editRole = (params: {}, header: string) => {
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  }
  return http.post<String>(`/pages/role!editRole.action`, qs.stringify(newobj)); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 批量删除客户
export const deleteRole = (params: string) => {
  return http.post<String>(`/pages/role!deleteRole.action` + params, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
};

// 导出模板
export const tempRole = (params: OrgManager.ReqOrgManagerParams) => {
  return http.download(`importFile/Role.zip`, params);
};

// importITSOPUser
export const importRoleData = (params: FormData) => {
  return http.post(`/pages/role!importRoleData.action`, params);
};

// 导出角色数据
export const exportRole = (params: OrgManager.ReqOrgManagerParams) => {
  let header = "roleQueryDto";
  let newobj = {};
  if (header != null && header != "") {
    Object.keys(params).forEach(key => {
      newobj[header + "." + `${key}`] = `${params[key]}`;
    });
  }
  return http.downloaditsm(
    `/pages/role!exportRole.action?_search=false&nd=1720518116067&rows=15&page=1&sidx=roleId&sord=desc`,
    qs.stringify(newobj)
  );
};

// 获取当前登录用户信息
export const getCurrentLoginUser = () => {
  return http.post<String>(`/pages/user!getCurrentLoginUser.action`, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
  // return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/list`, params);
  // return http.postitsm<string>("" + `/pages/email!emailConnTest.action`, {},  params,header );
};

// 获取权限菜单树
export const findTree = () => {
  return http.post<String>(`/pages/function!findTree.action?_=1721183636427&resCode=`, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
  // return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/list`, params);
  // return http.postitsm<string>("" + `/pages/email!emailConnTest.action`, {},  params,header );
};

// 获取角色权限
export const getResourceByRoleId = (id: string) => {
  return http.post<String>(`/pages/role!getResourceByRoleId.action?roleId=` + id, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
  // return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/list`, params);
  // return http.postitsm<string>("" + `/pages/email!emailConnTest.action`, {},  params,header );
};

// 操作权限列表
export const operationFind = (id: string) => {
  return http.post<String>(`/pages/operation!find.action?rows=10000&functionNo=` + id, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
  // return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/list`, params);
  // return http.postitsm<string>("" + `/pages/email!emailConnTest.action`, {},  params,header );
};

// 操作权限列表
export const setResourceByRoleIds = (str: string) => {
  return http.post<String>(`/pages/role!setResourceByRoleIds.action?str=` + str, qs.stringify({})); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
  // return http.post<ResPage<User.ResUserList>>(PORT1 + `/user/list`, params);
  // return http.postitsm<string>("" + `/pages/email!emailConnTest.action`, {},  params,header );
};

// 导出用户模板
export const tempUser = (params: OrgManager.ReqOrgManagerParams) => {
  return http.download(`importFile/User.zip`, params);
};

// importUserData
export const importUserData = (params: FormData) => {
  return http.post(`/pages/user!importUserData.action`, params);
};
